import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:mr_camera/model/UserDetail.dart';

import 'mr_camera_platform_interface.dart';

/// An implementation of [MrCameraPlatform] that uses method channels.
class MethodChannelMrCamera extends MrCameraPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  static MethodChannel methodChannel = const MethodChannel('com.acraftsman/mr_camera');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<void> startScanService() async {
    await methodChannel.invokeMethod<void>('startScanService');
  }

  @override
  Future<void> stopScanService() async {
    await methodChannel.invokeMethod<void>('stopScanService');
  }

  @override
  Future<bool> isScanServiceRunning() async {
    return await methodChannel.invokeMethod('isScanServiceRunning');
  }

  @override
  Future<String> startClientActivity(UserDetail userDetail, String snapshotFilePath) async {
    return await methodChannel
        .invokeMethod('startClientActivity',{'userDetail':jsonEncode(userDetail.toMap()),'snapshotFilePath': snapshotFilePath});
  }

  @override
  Future<int> getIpCamCount() async {
    return await methodChannel.invokeMethod('getIpCamCount');
  }

  @override
  Future<void> rediscoverCameras() async {
    return await methodChannel.invokeMethod('rediscoverCameras');
  }

}
